<template>
	<view class="center">
		<view class="logo" @click="goLogin" :hover-class="!login ? 'logo-hover' : ''">
			<image class="logo-img" :src="login ? userInfo.userImageUrl :avatarUrl"></image>
			<view class="logo-title">
				<text class="uer-name">Hi，{{login ? userInfo.name : '您未登录'}}</text>
				<text class="go-login navigat-arrow" v-if="!login">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item border-bottom"  @click="myCollect()">
				<text class="list-icon">&#xe60c;</text>
				<text class="list-text">收藏图片</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item border-bottom"  @click="addPhotoCircle()">
				<text class="list-icon">&#xe60b;</text>
				<text class="list-text">发布图友圈</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item border-bottom" @click="myPhoto()">
				<text class="list-icon">&#xe60b;</text>
				<text class="list-text">管理图片</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item" @click="uploadPhoto()">
				<text class="list-icon">&#xe61a;</text>
				<text class="list-text">上传图片</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item border-bottom" @click="photoRecommend()">
				<text class="list-icon">&#xe60b;</text>
				<text class="list-text">图片推荐</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item" @click="removeLogin()">
				<text class="list-icon">&#xe609;</text>
				<text class="list-text">退出登录</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				login: false,
				avatarUrl: "../../static/logo.png",
				userInfo: {}
			}
		},
		onShow: function(options) {
			var that = this
			uni.showLoading({
				title: "页面刷新中"
			});
			setTimeout(function() {
				var userInfo = (uni.getStorageSync('userInfo'))
				//判断是否有缓存
				if (userInfo != "") {
					console.log(1)
					//取值绑值
					that.userInfo = userInfo
					that.login = true
				} else {
					that.login = false
				}
				uni.hideLoading();
			}, 500);
		},
		methods: {
			//退出登录
			removeLogin() {
				var that = this
				uni.showLoading({
					title: "退出登录成功"
				});
				setTimeout(function() {
					uni.removeStorageSync("token")
					uni.removeStorageSync("userInfo")
					//刷新当前页面
					that.userInfo = {}
					that.login = false
					uni.hideLoading();
				}, 500);
			},
			goLogin() {
				if (!this.login) {
					uni.navigateTo({
						url: "../login/login"
					})
				} else {
					//修改个人信息
					uni.navigateTo({
						url: "../update/update"
					})
				}
			},
			//跳转到上传图片界面
			uploadPhoto(){
				//上传图片界面
				uni.navigateTo({
					url:"../upload/upload"
				})
			},
			//跳转到我的图片页面
			myPhoto(){
				uni.navigateTo({
					url: "../myPhoto/myPhoto"
				})
			},
			//跳转到推荐图片页面
			photoRecommend() {
				uni.navigateTo({
					url: "../photoRecommend/photoRecommend"
				})
			},
			//跳转到我的收藏页面
			myCollect(){
				uni.navigateTo({
					url:"../collect/myCollect"
				})
			},
			//跳转图友圈发布界面
			addPhotoCircle(){
				uni.navigateTo({
					url:"/pages/friendsCircle/releaseCircle"
				})
			}
		}
	}
</script>

<style>
</style>
